home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / frontend / flyEditor / MainFrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-30  |  6.9 KB  |  310 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "flyEditor.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "LeftView.h"
  9. #include "flyEditorView.h"
  10. #include "flyRenderView.h"
  11. #include "flyEditorDoc.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. extern CFlyRenderView *rv;
  20. extern int active_mode;
  21. CDialogBar *dlgBar=0;
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CMainFrame
  24.  
  25. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  26.  
  27. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  28.     //{{AFX_MSG_MAP(CMainFrame)
  29.     ON_WM_CREATE()
  30.     ON_COMMAND(ID_TOOLS_UNPAKFPK, OnToolsUnpakfpk)
  31.     ON_COMMAND(ID_TOOLS_PAKFPK, OnToolsPakfpk)
  32.     ON_COMMAND(ID_TOOLS_LIGHT, OnToolsLight)
  33.     ON_COMMAND(ID_TOOLS_VIEWPVS, OnToolsViewpvs)
  34.     //}}AFX_MSG_MAP
  35.     ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
  36.     ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
  37. END_MESSAGE_MAP()
  38.  
  39. static UINT indicators[] =
  40. {
  41.     ID_SEPARATOR,           // status line indicator
  42.     ID_INDICATOR_CAPS,
  43.     ID_INDICATOR_NUM,
  44.     ID_INDICATOR_SCRL,
  45. };
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CMainFrame construction/destruction
  49.  
  50. CMainFrame::CMainFrame()
  51. {
  52. }
  53.  
  54. CMainFrame::~CMainFrame()
  55. {
  56. }
  57.  
  58. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  59. {
  60.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  61.         return -1;
  62.     
  63.     if (!m_wndToolBar.CreateEx(this) ||
  64.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  65.     {
  66.         TRACE0("Failed to create toolbar\n");
  67.         return -1;      // fail to create
  68.     }
  69.     if (!m_wndDlgBar.Create(this, IDR_MAINFRAME, 
  70.         CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
  71.     {
  72.         TRACE0("Failed to create dialogbar\n");
  73.         return -1;        // fail to create
  74.     }
  75.  
  76.     if (!m_wndReBar.Create(this) ||
  77.         !m_wndReBar.AddBar(&m_wndToolBar) ||
  78.         !m_wndReBar.AddBar(&m_wndDlgBar))
  79.     {
  80.         TRACE0("Failed to create rebar\n");
  81.         return -1;      // fail to create
  82.     }
  83.  
  84.     if (!m_wndStatusBar.Create(this) ||
  85.         !m_wndStatusBar.SetIndicators(indicators,
  86.           sizeof(indicators)/sizeof(UINT)))
  87.     {
  88.         TRACE0("Failed to create status bar\n");
  89.         return -1;      // fail to create
  90.     }
  91.  
  92.     dlgBar=&m_wndDlgBar;
  93.  
  94.     m_wndDlgBar.GetDlgItem(IDC_NUM)->EnableWindow(active_mode);
  95.     m_wndDlgBar.GetDlgItem(IDC_SPIN)->EnableWindow(active_mode);
  96.     m_wndDlgBar.GetDlgItem(IDC_ACTIVATE)->EnableWindow(active_mode);
  97.     m_wndDlgBar.GetDlgItem(IDC_DESTROY)->EnableWindow(active_mode);
  98.  
  99.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  100.  
  101.     return 0;
  102. }
  103.  
  104. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
  105.     CCreateContext* pContext)
  106. {
  107.     // create splitter window
  108.     if (!m_wndSplitter.CreateStatic(this, 1, 3))
  109.         return FALSE;
  110.  
  111.     if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(180, 100), pContext) ||
  112.         !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CFlyEditorView), CSize(180, 100), pContext) ||
  113.         !m_wndSplitter.CreateView(0, 2, RUNTIME_CLASS(CFlyRenderView), CSize(100, 100), pContext))
  114.     {
  115.         m_wndSplitter.DestroyWindow();
  116.         return FALSE;
  117.     }
  118.  
  119.     OnViewStyle(ID_VIEW_DETAILS);
  120.  
  121.     return TRUE;
  122. }
  123.  
  124. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  125. {
  126.     if( !CFrameWnd::PreCreateWindow(cs) )
  127.         return FALSE;
  128.     return TRUE;
  129. }
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CMainFrame diagnostics
  133.  
  134. #ifdef _DEBUG
  135. void CMainFrame::AssertValid() const
  136. {
  137.     CFrameWnd::AssertValid();
  138. }
  139.  
  140. void CMainFrame::Dump(CDumpContext& dc) const
  141. {
  142.     CFrameWnd::Dump(dc);
  143. }
  144.  
  145. #endif //_DEBUG
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CMainFrame message handlers
  149.  
  150. CFlyEditorView* CMainFrame::GetRightPane()
  151. {
  152.     CWnd* pWnd = m_wndSplitter.GetPane(0, 1);
  153.     CFlyEditorView* pView = DYNAMIC_DOWNCAST(CFlyEditorView, pWnd);
  154.     return pView;
  155. }
  156.  
  157. void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
  158. {
  159.     CFlyEditorView* pView = GetRightPane(); 
  160.  
  161.     if (pView == NULL)
  162.         pCmdUI->Enable(FALSE);
  163.     else
  164.     {
  165.         DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;
  166.  
  167.         if (pCmdUI->m_nID == ID_VIEW_LINEUP)
  168.         {
  169.             if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
  170.                 pCmdUI->Enable();
  171.             else
  172.                 pCmdUI->Enable(FALSE);
  173.         }
  174.         else
  175.         {
  176.             pCmdUI->Enable();
  177.             BOOL bChecked = FALSE;
  178.  
  179.             switch (pCmdUI->m_nID)
  180.             {
  181.             case ID_VIEW_DETAILS:
  182.                 bChecked = (dwStyle == LVS_REPORT);
  183.                 break;
  184.  
  185.             case ID_VIEW_SMALLICON:
  186.                 bChecked = (dwStyle == LVS_SMALLICON);
  187.                 break;
  188.  
  189.             case ID_VIEW_LARGEICON:
  190.                 bChecked = (dwStyle == LVS_ICON);
  191.                 break;
  192.  
  193.             case ID_VIEW_LIST:
  194.                 bChecked = (dwStyle == LVS_LIST);
  195.                 break;
  196.  
  197.             default:
  198.                 bChecked = FALSE;
  199.                 break;
  200.             }
  201.  
  202.             pCmdUI->SetRadio(bChecked ? 1 : 0);
  203.         }
  204.     }
  205. }
  206.  
  207.  
  208. void CMainFrame::OnViewStyle(UINT nCommandID)
  209. {
  210.     CFlyEditorView* pView = GetRightPane();
  211.  
  212.     if (pView != NULL)
  213.     {
  214.         DWORD dwStyle = -1;
  215.  
  216.         switch (nCommandID)
  217.         {
  218.         case ID_VIEW_LINEUP:
  219.             {
  220.                 CListCtrl& refListCtrl = pView->GetListCtrl();
  221.                 refListCtrl.Arrange(LVA_SNAPTOGRID);
  222.             }
  223.             break;
  224.  
  225.         case ID_VIEW_DETAILS:
  226.             dwStyle = LVS_REPORT;
  227.             break;
  228.  
  229.         case ID_VIEW_SMALLICON:
  230.             dwStyle = LVS_SMALLICON;
  231.             break;
  232.  
  233.         case ID_VIEW_LARGEICON:
  234.             dwStyle = LVS_ICON;
  235.             break;
  236.  
  237.         case ID_VIEW_LIST:
  238.             dwStyle = LVS_LIST;
  239.             break;
  240.         }
  241.  
  242.         if (dwStyle != -1)
  243.             pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
  244.     }
  245. }
  246.  
  247. void CMainFrame::OnToolsUnpakfpk() 
  248. {
  249.     CFileDialog fd(TRUE,"fpk",0,OFN_NOCHANGEDIR|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST,"Fly3D Pak (*.fpk)|*.fpk||",this);
  250.     if (fd.DoModal()==IDOK)
  251.     {
  252.         char file[256];
  253.         strcpy(file,GetRightPane()->GetDocument()->flysdkpath);
  254.         strcat(file,"flypak.exe \"");
  255.         strcat(file,fd.GetPathName());
  256.         strcat(file,"\"");
  257.         WinExec(file,SW_SHOW);
  258.     }
  259. }
  260.  
  261. void CMainFrame::OnToolsPakfpk() 
  262. {
  263.     BROWSEINFO bi;     
  264.     char Buffer[MAX_PATH]; 
  265.     LPITEMIDLIST pidlBrowse;    
  266.     LPMALLOC ppMalloc;
  267.     
  268.     SHGetMalloc( &ppMalloc );
  269.  
  270.     bi.hwndOwner=m_hWnd;
  271.     bi.pidlRoot = 0; 
  272.     bi.pszDisplayName = Buffer;     
  273.     bi.lpszTitle = "Select directory to convert into a Fly3D Pak file"; 
  274.     bi.ulFlags = BIF_RETURNONLYFSDIRS;
  275.     bi.lpfn = NULL;     
  276.     bi.lParam = 0;  
  277.  
  278.     pidlBrowse = SHBrowseForFolder(&bi);     
  279.     if (pidlBrowse != NULL) 
  280.         {  
  281.         if (SHGetPathFromIDList(pidlBrowse, Buffer)) 
  282.             {
  283.             char file[256];
  284.             strcpy(file,GetRightPane()->GetDocument()->flysdkpath);
  285.             strcat(file,"flypak.exe \"");
  286.             strcat(file,Buffer);
  287.             strcat(file,"\"");
  288.             WinExec(file,SW_SHOW);
  289.             }
  290.         ppMalloc->Free(pidlBrowse);
  291.         }
  292. }
  293.  
  294. void CMainFrame::OnToolsLight() 
  295. {
  296.     char file[256];
  297.     strcpy(file,GetRightPane()->GetDocument()->flysdkpath);
  298.     strcat(file,"flyLight.exe");
  299.     WinExec(file,SW_SHOW);
  300. }
  301.  
  302. void CMainFrame::OnToolsViewpvs() 
  303. {
  304.     char file[256];
  305.     strcpy(file,GetRightPane()->GetDocument()->flysdkpath);
  306.     strcat(file,"flyPVS.exe");
  307.     WinExec(file,SW_SHOW);
  308. }
  309.  
  310.